package com.cinema.entity.ticket;

import com.cinema.entity.hall.Seat;
import com.cinema.entity.movie.Schedule;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

/**
 * 电影票实体类
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Ticket implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    private String ticketId;      // 票号（唯一）
    private Schedule schedule;    // 关联场次
    private Seat seat;            // 座位信息
    private double payAmount;     // 支付金额
    private LocalDateTime buyTime; // 购买时间
    private boolean isRefunded;   // 是否已退票

    public Ticket(Schedule schedule, Seat seat, double payAmount) {
        this.ticketId = "T" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
        this.schedule = schedule;
        this.seat = seat;
        this.payAmount = payAmount;
        this.buyTime = LocalDateTime.now();
        this.isRefunded = false;
    }

    @Override
    public String toString() {
        return String.format(
                "===== 电影票 =====\n票号：%s\n影片：%s\n场次：%s\n时间：%s\n放映厅：%s\n座位：%s\n金额：%.2f元\n购买时间：%s\n状态：%s",
                ticketId,
                schedule.getMovie().getMovieName(),
                schedule.getScheduleId(),
                schedule.getShowTime().format(FORMATTER),
                schedule.getHall().getHallName(),
                seat.getSeatId(),
                payAmount,
                buyTime.format(FORMATTER),
                isRefunded ? "已退票" : "正常"
        );
    }
}
